home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 1146 / 1146.xpi / chrome / screengrab.jar / content / Editor.js < prev    next >
Text File  |  2009-03-09  |  2KB  |  64 lines

  1.  
  2. screengrab.Editor = {
  3.     replaceChar : "_",
  4.     fileNameRegEx : new RegExp('[,/\:*?""<>|]', 'g'),
  5.     
  6.     grab : function(target, capture) {
  7.         var mainWindow = window.opener;
  8.         var that = this;
  9.         var thatWindow = window;
  10.         mainWindow.sg.Grab2(target, capture, function(canvas) {
  11.             var doc = window.opener.sg.Browser.contentDocument();
  12.             thatWindow.focus();
  13.             that.canvas = canvas;
  14.             that.sourceUri = doc.URL;
  15.             that.title = doc.title;
  16.             document.getElementById('fileName').value = doc.title.replace(this.fileNameRegEx, this.replaceChar);
  17.             that.fillImage(canvas);
  18.         });
  19.     },
  20.     
  21.     doAction : function(actionName) {
  22.         var action = eval(" new window.opener.sg." + actionName + "()");
  23.         action.doAction(this.canvas);
  24.     },
  25.     
  26.     fillImage: function(canvas) {
  27.         var image = document.getElementById("grabbedImage");
  28.         var width = canvas.width;
  29.         var height = canvas.height;
  30.         
  31.         if (width < 500) {
  32.             xScale = 1;
  33.         } else {
  34.             xScale = 500 / width;
  35.         }
  36.         if (height < 500) {
  37.             yScale = 1;
  38.         } else {
  39.             yScale = 500 / height;
  40.         }
  41.         var scale = xScale < yScale ? xScale : yScale;
  42.         image.width = canvas.width * scale;
  43.         image.height = canvas.height * scale;
  44.         image.src = canvas.toDataURL("image/png", "");
  45.         
  46.         var dimensions = document.getElementById("dimensions");
  47.         dimensions.value = canvas.width + "x" + canvas.height;
  48.         
  49.         var zoom = document.getElementById("zoom");
  50.         zoom.value = Math.round(scale * 100) + "%";
  51.         window.sizeToContent();
  52.     },
  53.     
  54.     doScrnShotsUpload: function() {
  55.         var shotData = new window.opener.sg.ScrnShots.ShotData();
  56.         shotData.fileName = document.getElementById('fileName').value;
  57.         shotData.tags = "";
  58.         shotData.description = this.title;
  59.         shotData.sourceUri = this.sourceUri;
  60.         window.openDialog("chrome://screengrab/content/ScrnShotsUpload.xul", "scrnshots", "chrome,centerscreen,modal", {shotData: shotData});
  61.         var action = new window.opener.sg.UploadScrnshotsAction(shotData);
  62.         action.doAction(this.canvas);
  63.     }
  64. }